const { Sequelize } = require("sequelize");
const config = require("../config/config");

const connection = new Sequelize(
  config.db.db,
  config.db.username,
  config.db.password,
  {
    host: config.db.url,
    port: config.db.port,
    dialect: "mysql",
    logging: (msg) => {
      console.log("msg", msg);
    },
    timezone: "+08:00",
    dialectOptions: {
      charset: "utf8",
    },
  }
);

// 测试连接
connection
  .authenticate()
  .then((_) => {
    console.log("数据库连接成功!");
  })
  .catch((err) => {
    console.log("数据库连接失败! ", err);
  });

module.exports = connection;
